<template>
  <body id="login">
    <el-form class="login-form"
    :model="loginForm"
    label-position="left"
    label-width="80px"
    ref="loginForm"
    >
      <h3>欢迎来到论文管理系统</h3>
      <el-row>
        <el-form-item label="用户名" >
          <el-input type="text" v-model="loginForm.username" prefix-icon="el-icon-user" size="medium"></el-input>
        </el-form-item>
      </el-row>
      <el-row>
        <el-form-item label="密码">
          <el-input type="password" v-model="loginForm.password"  prefix-icon="el-icon-key" size="medium"></el-input>
        </el-form-item>
      </el-row>
      <el-row>
        <el-col span="10">
          <el-form-item label="验证码" >
            <el-input type="text" v-model="loginForm.code" prefix-icon="el-icon-edit" style="width: 100px"></el-input>
          </el-form-item>
        </el-col>
        <img width="160px" onclick="this.src='http://localhost:8444/createImageCode?d='+new Date()*1" src="http://localhost:8444/createImageCode"/>
      </el-row>
      <el-button type="primary" @click="handleLogin">登录</el-button>
    </el-form>
  </body>
</template>

<script>
export default {
  name: 'Login',
  data () {
    return {
      loginForm: {
        username: '',
        password: '',
        code: ''
      }
    }
  },
  methods: {
    handleLogin () {
      var _this = this
      // console.log(this.$store.state)
      this.$axios.post('/login', {
        username: this.loginForm.username,
        password: this.loginForm.password
      }).then(successResponse => {
        if (successResponse.data.code === 200) {
          _this.$store.commit('login', _this.loginForm)
          var path = this.$route.query.redirect
          this.$router.replace({
            path: path === '/' || path === undefined ? '/index' : path
          })
        }
      }).catch(failResponse => {
      })
    }
  }
}
</script>

<style scoped>
#login{
  background: url("../assets/loginBackground.jpg") no-repeat ;
  background-position: center;
  height: 100%;
  width: 100%;
  background-size: cover;
  position: fixed;
}
html,body{
  margin:0;
  padding:0;
}
.login-form{
  border-radius: 20px;
  margin: 200px auto;
  width:350px;
  border:2px solid lightblue;
  padding:20px;
  background: #ffffff;

}
</style>
